﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI;
using DevExpress.Web.ASPxHeadline;
using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxCallback;
using DevExpress.Web.ASPxGridView;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Interface;
using LMD.Lib.Controls;

public partial class CDList : ICPRelationshipPage
{
    
    
    #region Properties
    
    #endregion Properties

    #region Event Handlers

    protected override void Page_Load(object sender, EventArgs e)
    {
        m_lsPermittedRoles.Add(ICPUserRole.CAR);
        base.Page_Load(sender, e);

        Page.Title = "ICP Lintasarta: Relationship, Eval, Config & Datek - List";
        if (!IsPostBack && !IsCallback)
        {
            
        }
        InitKonfigDatekList();
    }

    public void HandleAll()
    {
        Session[KSession.CV_STARTDATE] = new DateTime();
        Session[KSession.CV_ENDDATE] = new DateTime();
        InitKonfigDatekList();
    }

    //add by rista
    public void HandleFilter(String sxParameter)
    {
        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);

        DateTime dtmStart = DateTime.Now;
        DateTime dtmEnd = DateTime.Now;

        if (!String.IsNullOrEmpty(sxSplitted[1]))
        {
            dtmStart = Convert.ToDateTime(sxSplitted[1]);
        }
        if (!String.IsNullOrEmpty(sxSplitted[2]))
        {
            dtmEnd = Convert.ToDateTime(sxSplitted[2]);
        }
        Session[KSession.CV_STARTDATE] = dtmStart;
        Session[KSession.CV_ENDDATE] = dtmEnd;
     
        InitKonfigDatekList();
    }

    protected void dgKonfigDatek_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        if (e.Parameters.ToUpper().StartsWith("FILTER"))
        {
            HandleFilter(e.Parameters);
        }
        else if (e.Parameters.ToUpper().StartsWith("ALL"))
        {
            HandleAll();
        }
    }

	protected void btnExport_Click(object sender, EventArgs e)
    {
        String sxFilename = String.Format("Eval, Config & Datek List - {0}", DateTime.Now.ToString());
        dgExporter.WriteXlsToResponse(sxFilename);
    }
    #endregion Event Handlers

    #region Custom Methods
    protected override void DoSearch(String sxSearchQuery)
    {
        throw new NotImplementedException();
    }
    public void InitKonfigDatekList()
    {
        //Edited by Rista
        DateTime dtmStart = Session[KSession.CV_STARTDATE] != null ?
            Convert.ToDateTime(Session[KSession.CV_STARTDATE]) :
            new DateTime();
        DateTime dtmEnd = Session[KSession.CV_ENDDATE] != null ?
            Convert.ToDateTime(Session[KSession.CV_ENDDATE]) :
            new DateTime();
        int iStartDate = dtmStart.Day;
        int iEndDate = dtmEnd.Day;
        int iStartMonth = dtmStart.Month;
        int iStartYear = dtmStart.Year;
        int iEndMonth = dtmEnd.Month;
        int iEndYear = dtmEnd.Year;
        //--End of Edited

        Cached.KonfigurasiDatekTable cachedKonfigDatek = new Cached.KonfigurasiDatekTable();
        //DataTable dtKonfigDatek = cachedKonfigDatek.LoadCDList();
        DataTable dtKonfigDatek = cachedKonfigDatek.LoadCDList(iStartDate, iEndDate, iStartMonth, iStartYear, iEndMonth, iEndYear);

        dgKonfigDatek.DataSource = dtKonfigDatek;
        dgKonfigDatek.DataBind();    
    }
    #endregion Custom Methods
   
}
